<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<TITLE></TITLE>
		<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
		<link rel="stylesheet" type="text/css" href="../Meta.css">
	</HEAD>
	<BODY>
		<H1>NullReferenceException</H1>
		<H2>What it means</H2>
		<P>In some sense, this is just a variant on the <A href="ArgumentTypeException.htm">ArgumentTypeException</A>
			or the <A href="InvalidCastException.htm">InvalidCastException</A>.&nbsp; 
			Literally, this means some piece of code tried to use <FONT face="Arial">null </FONT>
			in an operation for which it's unsuitable.&nbsp; Of course there are very few 
			operations for which it isn't unsuitable - it's not a valid parameter for most 
			operations, although you can store it in variables and check whether variables 
			have it as a value.</P>
		<H2>What causes it</H2>
		<P>Usually, this means one of the following:</P>
		<UL>
			<LI>
				Some procedure was passed <FONT face="Arial">null</FONT> as an argument but the 
				procedure wasn't written to handle <FONT face="Arial">null</FONT> as an 
				argument, so it went ahead and tried to add 7 to it (can't add number to <FONT face="Arial">
					null</FONT>), or ask for its 4th element (it doesn't have any elements - 
				it's not a list), call it as a procedure (its not a procedure), etc.</LI>
			<LI>
				Some procedure returned <FONT face="Arial">null</FONT> as a value and the 
				procedure calling it wasn't written to handle <FONT face="Arial">null</FONT> as 
				a return value, so again, it went on to try to use it for some nonsensical 
				purpose.</LI>
			<LI>
				Some other languages allow you to declare variables without giving them 
				values.&nbsp; A common error is to forget to give a variable a value before 
				trying to use its value for something and under .NET, this usually triggers a 
				NullReferenceException.&nbsp; So if this occcurs when calling code written in 
				some other language, this could potentially indicate a bug in the code.</LI></UL>
		<H2>What to do</H2>
		<P>As with&nbsp;<A href="InvalidCastException.htm">InvalidCastException</A>, this 
			is a low-level error generated by .NET, not something generated by the Meta 
			interpreter.&nbsp; As a result, it doesn't come with a lot of debugging 
			information.&nbsp; But you can start by looking at the expression on top of the 
			stack to see if null occurs in any of its arguments or local variables.&nbsp; 
			However, there are some cases in which this error will be quite difficult to 
			pin down because the error is inside some C# code that you don't have access 
			to.</P>
	</BODY>
</HTML>
